CFID3
What Is the CFID3 Component?
CFID3 is based on the open-source JD3Lib Project (located at http://sourceforge.net/projects/jd3lib), which allows you to manipulate the ID3 tags of MP3s natively with ColdFusion MX. Additionally you can update a database with parsed ID3 information. Please refer to the component documentation for a complete list of methods and their functions.
Installing the CFID3 Component
The CFID3 component is easy to install:
- Place jd3lib-a4.jar in the folder WEB-INF/lib.
- Restart ColdFusion MX.
- Place cfid3.cfc in any folder off your web root and call the appropriate methods.
Parsing ID3 Tags from an MP3 File
Here's how you use CFID3 to parse ID3 tags:
- Load the MP3 file into the component with the setFile(filePath) method.
- Set the tagging type to read from using setTagType(taggingType) or autoTagType(). (This is optional.)
- Call the method getID3().
For example:
cfid3 = createObject("component", "cfid3 cfc path");
cfid3.setFile("D:\My Music\SomeSong.mp3");
cfid3.setTagType("ID3V2_ONLY");
myID3 = cfid3.getID3();
The autoTagType() method sets the tagging type based on a comparison of the ID3 tag's byte size. Valid tag types values include BOTH_TAGS, ID3V2_ONLY, ID3V1_ONLY, EXISTING_TAGS_ONLY, or numeric values 0–4.
Adding ID3 Tags to an MP3 File
Here's how you add ID3 tags:
- Load the MP3 file into the component with the setFile(filePath) method.
- Set the tagging type to write to using setTagType(taggingType) or autoTagType(). (This is optional.)
- Create an MP3 structure with the createMP3Struct() method.
- Update the MP3 structure and set the ID3 fields with the setID3(mp3Structure) method.
For example:
cfid3 = createObject("component", "cfid3 cfc path");
cfid3.setFile("D:\My Music\SomeSong.mp3");
cfid3.setTagType("BOTH_TAGS");
myID3 = cfid3.getMP3Struct();
myID3.artist = "Some Artist";
myID3.title = "Some Song";
myID3.genre = "Rock";
cfid3.setID3(myID3);
By default all changes are written to the file automatically. If specified with the write argument, changes must be written to the file with the writeTags() method.
Inserting ID3 Tags into a Database
The example below creates a database connection that inserts the Artist and Genre fields into the table. If the column name is not specified, the field isn't inserted into the database. Note that in the example the genre is inserted into the database as a number. The valid options for the type key are "string" or "numeric." Rather then updating the database connection externally, the default settings may be hard-coded by editing the createDBStruct() method directly:
- Call the createDBStruct() method.
- Assign the database name to the name key. (This is required.)
- Assign the connection username and password. (This is optional.)
- Assign the table name and primary key. (This is required.)
- Assign the column names from your table to the corresponding name keys. (This is optional.)
- Initialize the database connection by passing the newly formed database structure to the method initDBConnection(dbStructure).
For example:
cfid3 = createObject("component", "cfid3 cfc path");
myDB = cfid3.createDBStruct();
myDB.name = "myDatasource";
myDB.username = "myUsername";
myDB.password = "myPassword";
myDB.table = "myTableName";
myDB.primaryKey = "myTableKey";
myDB.col.artist.name = "e;artistColumn";
myDB.col.genre.name = "genreColumn";
myDB.col.genre.type = "numeric";
cfid3.initDBConnection(myDB);